package my.jieh.tips.swing;

import java.util.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;

public class SpinDemo3 {
  public static void main(String args[]) {

    // create a JFrame

    JFrame frame = new JFrame("SpinDemo3");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // create a JSpinner set to the current
    // date, with increment/decrement
    // set to minutes

    final SpinnerModel sm =
        new SpinnerDateModel(new Date(),
                             null, null, Calendar.MINUTE);
    JSpinner jsp = new JSpinner(sm);

    // add a change listener for the JSpinner

    jsp.addChangeListener(
        new ChangeListener() {
      public void stateChanged(
          ChangeEvent e) {
        Date d = (Date) sm.getValue();
        System.out.println(
            "new date: " + d);
      }
    });

    // create a JPanel

    JPanel panel = new JPanel();
    panel.setPreferredSize(
        new Dimension(300, 300));
    panel.add(jsp);
    frame.getContentPane().add(panel);

    // display the frame

    frame.pack();
    frame.setVisible(true);
  }

}// end class